package com.example.task;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @description
 * @author: ruanchengzhi
 * @create: 2021-07-30 15:59
 **/
@Component
@EnableScheduling
public class BatchTaskJob {

    @Autowired
    SimpleJobLauncher jobLauncher;

    @Autowired
    Job batchJob;

    @Scheduled(cron = "0 */2 * * * ?")
    public void job3() throws Exception {
        JobParameters jobParameter = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
        JobExecution run = jobLauncher.run(batchJob, jobParameter);
        System.out.println(run.getId());
    }
}
